<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-page-container">
  <a [routerLink]="['..']" class="gv-back-link"><small><< Back to factors</small></a>
  <h1>{{factor.name}}</h1>
  <div fxLayout="row">
    <div fxLayout="column" fxFlex="70">
      <form #factorForm="ngForm">
        <div class="gv-form-section">
          <mat-form-field appearance="outline" floatLabel="always">
            <mat-label>Name</mat-label>
            <input matInput type="text" placeholder="Name" name="name" [(ngModel)]="factor.name" required [readonly]="!editMode">
            <mat-hint>Factor name</mat-hint>
          </mat-form-field>
          <mat-form-field appearance="outline" floatLabel="always">
            <mat-label>Factor type</mat-label>
            <input matInput type="text" placeholder="Factor type" name="factorType" [(ngModel)]="factor.factorType" required disabled>
            <mat-hint>Type of the factor</mat-hint>
          </mat-form-field>
        </div>

        <div class="gv-form-section">
          <div class="gv-form-section-title">
            <h5>Configuration</h5>
            <mat-divider></mat-divider>
          </div>
          <div>
            <factor-form *ngIf="factor" [factorConfiguration]="factorConfiguration" [factorSchema]="factorSchema" (configurationCompleted)="enableFactorUpdate($event)"></factor-form>
          </div>
        </div>

        <div fxLayout="row" *ngIf="editMode">
          <button mat-raised-button color="primary" [disabled]="(!factorForm.valid || factorForm.pristine) && (!configurationIsValid || configurationPristine) && !formChanged" (click)="update()">SAVE</button>
        </div>
      </form>

      <div *hasPermission="['domain_factor_delete']" class="gv-page-delete-zone" fxLayout="column">
        <p>This operation cannot be undone.</p>
        Factor will be deleted, applications will not be able to use this factor authentication anymore.
        <div class="gv-page-delete-button" fxLayout="row">
          <span fxFlex></span>
          <button mat-raised-button color="warn" (click)="delete($event)">DELETE</button>
        </div>
      </div>
    </div>
    <div class="gv-page-description" fxFlex>
      <h3>Manage Multi-factor Authentication</h3>
      <div class="gv-page-description-content">
        <p>
          Multi-factor Authentication is an additional step during the login flow in order to enforce access control.
        </p>
      </div>
    </div>
  </div>
</div>
